package com.wsz.eduservice.controller.front;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wsz.commonutils.R;
import com.wsz.eduservice.pojo.Course;
import com.wsz.eduservice.pojo.Teacher;
import com.wsz.eduservice.pojo.frontvo.CourseFrontVo;
import com.wsz.eduservice.service.CourseService;
import com.wsz.eduservice.service.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/eduservice/teacherfront")
public class TeacherFrontController {

    @Autowired
    private TeacherService teacherService;

    @Autowired
    private CourseService courseService;

    @PostMapping("/getTeacherFrontList/{page}/{limit}")
    public R getTeacherFrontList(@PathVariable long page,
                                 @PathVariable long limit){

        Page<Teacher> pageTeacher = new Page<>(page,limit);

        Map<String,Object> map= teacherService.getTeacherFrontList(pageTeacher);

        return R.ok().data(map);
    }

    @GetMapping("/getTeacherFrontInfo/{id}")
    public R getTeacherFrontInfo(@PathVariable String id) {

        Teacher byId = teacherService.getById(id);


        QueryWrapper<Course> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("teacher_id", id);

        List<Course> list = courseService.list(queryWrapper);

        return R.ok().data("teacher", byId).data("courseList", list);
    }
}
